import * as data from '@/constants/config.js'
import * as keyOperate from '@/utils/key-down'
import * as api from '@/api'
export default {
  namespaced: true,
  state: {
    // 初始数据(aside)
    list: [],
    showList:[],
    // 预览面板信息
    info: {},
    //数据库的数据
    oldList: [],
    //保存之前编辑过的数组ID
    oldListId : -1,
    //弹框
    dialogFormVisible : false,
  },
  mutations: {
    GET_SHOW_LIST(state, val) {
      if (keyOperate.isOp() == 'back') {
        state.showList = val.sort((a, b) => b.lel - a.lel)
      } else if (keyOperate.isOp() == 'forward') {
        state.showList = val.sort((a, b) => b.lel - a.lel)
      }else{
        keyOperate.getData(val)
        state.showList = val.sort((a, b) => b.lel - a.lel)
      }
    },
    GET_INFO (state, val) {
      state.info = val
    },
    SET_LIST (state, val) {
      state.list = val
    },
    SET_OLD_LIST (state, val) {
      state.oldList = val
    },
    GET_OLD_LIST_ID (state, id) {
      state.oldListId = id
    },
    IS_VISIABLE (state, val) {
      state.dialogFormVisible = val
    },
  },
  actions: {
    async asideData(ctx) {
      const data = await api.getAsideData();
      ctx.commit('SET_LIST', data);
    },
    async getOldList(ctx) {
      const data = await api.getAll();
      ctx.commit('SET_OLD_LIST', data);
    },
  }
}
